//bange_simplesprite.cpp
//Copyright (C) 2010-2011 Oscar (.teri) Triano

//This program is free software: you can redistribute it and/or modify
//it under the terms of the GNU General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//(at your option) any later version.

//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU General Public License for more details.

//You should have received a copy of the GNU General Public License
//along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <bange_simplesprite.hpp>

void bange::simplesprite::RegisterVM(lua_State *vm){
	luaL_Reg method[] = {
	{NULL, NULL}};
	luaL_newmetatable(vm, "bange::simplesprite_method");
	luaL_register(vm, NULL, method);
	lua_pop(vm, 1);
}

bange::simplesprite::simplesprite(lua_State *vm): bange::object(vm){
	this->drawable = static_cast<sf::Sprite *>(this);
}

bange::simplesprite::~simplesprite(){
	cout << "bange::simplesprite destructor for: " << this << endl;
}

void bange::simplesprite::CleanVM(lua_State *vm){
	cout << "bange::simplesprite::CleanVM: " << this << endl;
	this->bange::behavior::CleanVM(vm);
	this->bange::animation::CleanVM(vm);
}

bool bange::simplesprite::NewIndex(lua_State *vm){
	//simplesprite, key, data
	if (this->bange::object::NewIndex(vm)){
		return true;}
	else if (this->bange::behavior::NewIndex(vm)){
		return true;}
	else if (this->bange::animation::NewIndex(vm)){
		return true;}
}

bool bange::simplesprite::Index(lua_State *vm){
	//simplesprite, key
	if (this->bange::object::Index(vm)){
		return true;}
	else if (this->bange::behavior::Index(vm)){
		return true;}
	else if (this->bange::animation::Index(vm)){
		return true;}
	lua_getfield(vm, LUA_REGISTRYINDEX, "bange::simplesprite_method");
	lua_getfield(vm, -1, lua_tostring(vm, 2));
	if (lua_isfunction(vm, -1)){
		return true;}
	lua_pop(vm, 1);
	return false;
}

void bange::simplesprite::Process(float time){
	this->bange::animation::Process(time);
}
